package pl.edu.agh.iosr.gamblingzone.model;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@AttributeOverride(name="id",
		column=@Column(name="GROUP_ID"))
@Entity(name="GROUPS")
public class Group extends IEntity {
	
	@Column(name="GROUPS_NAME", nullable=false)
	private String name;
	
	@Column(name="GROUPS_DESCRIPTION", nullable=false)
	private String description;
	
	@ManyToOne(targetEntity=Discipline.class, 
			cascade={CascadeType.PERSIST, CascadeType.MERGE})
	@JoinColumn(name = "DISCIPLINE_ID", nullable=false)
	private Discipline discipline;
	
	@OneToMany(mappedBy="group", cascade=CascadeType.ALL)
	@JoinColumn(name="GROUP_ID", nullable=false)
	private List<AbstractEvent> events = new LinkedList<AbstractEvent>();

	public Discipline getDiscipline() {
		return discipline;
	}

	public void setDiscipline(Discipline discipline) {
		this.discipline = discipline;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<AbstractEvent> getEvents() {
		return events;
	}

	public void setEvents(List<AbstractEvent> events) {
		this.events = events;
	}	
	
	public void addEvent(AbstractEvent ae) {
		ae.setGroup(this);
		this.events.add(ae);
	}
}
